package com.example.pipline.yu.normal.step;

import com.example.pipline.yu.normal.request.OrderItem;
import com.example.pipline.yu.normal.request.OrderRequest;
import com.example.pipline.yu.normal.PipelineContext;

// 步骤1：验证订单数据（无写操作）
public class ValidateOrderStep implements PipelineStep {
    @Override
    public void execute(PipelineContext context) {
        OrderRequest request = context.get("orderRequest");

        // 验证逻辑
        if (request.getItems() == null || request.getItems().isEmpty()) {
            context.setError("订单至少包含一个商品");
            return;
        }

        for (OrderItem item : request.getItems()) {
            if (item.getQuantity() <= 0) {
                context.setError("商品数量必须大于0: " + item.getProductId());
                return;
            }
        }
    }
}